<template>
  <el-container>
    <el-aside width="200px" style="border-right: 1px solid #ccc">
      <el-menu default-active="1" class="el-menu-vertical-demo" @select="handleSelect">
        <el-menu-item index="1" @click="goToUserInfo">
          <template #title>
            <el-icon><User /></el-icon>
            <span>用户信息</span>
          </template>
        </el-menu-item>
        <el-menu-item index="2" @click="goToRoleManage">
          <template #title>
            <el-icon><Setting /></el-icon>
            <span>角色管理</span>
          </template>
        </el-menu-item>
        <el-menu-item index="3" @click="goToEquipmentManage">
          <template #title>
            <el-icon><Tools /></el-icon>
            <span>装备管理</span>
          </template>
        </el-menu-item>
        <el-menu-item index="4" @click="goToTaskManage">
          <template #title>
            <el-icon><Document /></el-icon>
            <span>任务管理</span>
          </template>
        </el-menu-item>
        <el-menu-item index="5" @click="goToPlayerManage">
          <template #title>
            <el-icon><UserFilled /></el-icon>
            <span>玩家管理</span>
          </template>
        </el-menu-item>
        <el-menu-item index="6" @click="goToPlayerFeedbackManage">
          <template #title>
            <el-icon><ChatRound /></el-icon>
            <span>玩家反馈管理</span>
          </template>
        </el-menu-item>

        <!-- 公会管理折叠菜单 -->
        <el-sub-menu index="7">
          <template #title>
            <el-icon><House /></el-icon>
            <span>公会管理</span>
          </template>
          <el-menu-item index="7-1" @click="goToGuildManage">
            <span>公会管理</span>
          </el-menu-item>
          <el-menu-item index="7-2" @click="goToGuildMemberManage">
            <span>公会成员管理</span>
          </el-menu-item>
          <el-menu-item index="7-3" @click="goToGuildNoticeManage">
            <span>公会公告管理</span>
          </el-menu-item>
          <el-menu-item index="7-4" @click="goToGuildActivityManage">
            <span>公会活动管理</span>
          </el-menu-item>
          <el-menu-item index="7-5" @click="goToGuildContributionManage">
            <span>公会贡献管理</span>
          </el-menu-item>
          <el-menu-item index="7-6" @click="goToGuildDiplomacyManage">
            <span>公会外交关系</span>
          </el-menu-item>
        </el-sub-menu>

        <!-- 客服折叠菜单 -->
        <el-sub-menu index="8">
          <template #title>
            <el-icon><Service /></el-icon>
            <span>客服</span>
          </template>
          <el-menu-item index="8-1" @click="goToWorkOrder">
            <template #title>
              <el-icon><Document /></el-icon>
              <span>工单</span>
            </template>
          </el-menu-item>
          <el-menu-item index="8-2" @click="goToKnowledgeBase">
            <template #title>
              <el-icon><Document /></el-icon>
              <span>知识库</span>
            </template>
          </el-menu-item>
          <el-menu-item index="8-3" @click="goToPlayerCompensation">
            <template #title>
              <el-icon><Money /></el-icon>
              <span>玩家补偿</span>
            </template>
          </el-menu-item>
          <el-menu-item index="8-4" @click="goToPlayerBan">
            <template #title>
              <el-icon><Lock /></el-icon>
              <span>玩家封禁</span>
            </template>
          </el-menu-item>
<!--          <el-menu-item index="8-5" @click="goToRoleEquipmentLock">
            <template #title>
              <el-icon><Lock /></el-icon>
              <span>角色及装备锁定</span>
            </template>
          </el-menu-item>-->
        </el-sub-menu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header style="height: 55px; border-bottom: 1px solid #ccc">
        <!-- 头部内容 -->
        <div class="header-content">
          <div class="logo">游戏运营管理系统</div>
          <div class="user-info">
            <el-dropdown trigger="click">
              <span class="el-dropdown-link">
                {{ username }} <el-icon><CaretBottom /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>
      <el-main style="background-color: rgba(246, 249, 248)">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { useRouter } from "vue-router";
import {
  User, Setting, Tools, Document, UserFilled, ChatRound, House,
  Service, Money, Lock, CaretBottom
} from "@element-plus/icons-vue";
import { ref } from "vue";

const router = useRouter();
const username = ref(localStorage.getItem('username') || '管理员');

// 用户信息导航
const goToUserInfo = () => router.push({ name: "user-info" });

// 角色管理导航
const goToRoleManage = () => router.push({ name: "role-manage" });

// 装备管理导航
const goToEquipmentManage = () => router.push({ name: "equipment-manage" });

// 任务管理导航
const goToTaskManage = () => router.push({ name: "task-manage" });

// 玩家管理导航
const goToPlayerManage = () => router.push({ name: "player-manage" });

// 玩家反馈管理导航
const goToPlayerFeedbackManage = () => router.push({ name: "player-feedback-manage" });

// 公会管理导航
const goToGuildManage = () => router.push({ name: "guild-manage" });
const goToGuildMemberManage = () => router.push({ name: "guild-member-manage" });
const goToGuildNoticeManage = () => router.push({ name: "guild-notice-manage" });
const goToGuildActivityManage = () => router.push({ name: "guild-activity-manage" });
const goToGuildContributionManage = () => router.push({ name: "guild-contribution-manage" });
const goToGuildDiplomacyManage = () => router.push({ name: "guild-diplomacy-manage" });

// 客服导航
const goToWorkOrder = () => router.push({ name: "work-order-manage" });
const goToKnowledgeBase = () => router.push({ name: "knowledge-base-manage" });
const goToPlayerCompensation = () => router.push({ name: "player-compensation-manage" });
const goToPlayerBan = () => router.push({ name: "player-ban" });
//   const goToRoleEquipmentLock = () => router.push({ name: "role-equipment-lock-manage" });

// 退出登录
const logout = () => {
  localStorage.removeItem('token');
  localStorage.removeItem('username');
  router.push({ name: 'login' });
};

// 菜单选择事件
const handleSelect = (key, keyPath) => {
  console.log(key, keyPath);
};
</script>

<style scoped>
.el-header {
  height: 55px;
  border-bottom: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 18px;
  font-weight: bold;
}

.user-info {
  display: flex;
  align-items: center;
}
</style>